package edu.ynu.se.xiecheng.achitectureclass.dto;

import edu.ynu.se.xiecheng.achitectureclass.entity.Device;
import lombok.Getter;
import lombok.Setter;

import java.util.Set;
import java.util.stream.Collectors;

@Getter
@Setter
public class DeviceObject {

    private String deviceName;
    private String deviceNumber;
    private String deviceType;
    private String deviceUnit;
    private String deviceAddress;
    private Set<StatisticObject> statistics;

    public DeviceObject(Device device) {
        this.deviceName = device.getDeviceName();
        this.deviceNumber = device.getDeviceNumber();
        this.deviceType = device.getDeviceType();
        this.deviceUnit = device.getDeviceUnit();
        this.deviceAddress = device.getDeviceAddress();
        this.statistics = device.getStatistics().stream()
                .sorted((s1, s2) -> s2.getCreateTime().compareTo(s1.getCreateTime()))
                .limit(35)
                .map(StatisticObject::new)
                .collect(Collectors.toSet());
    }

}
